import api from '../../api';
import { message } from 'antd';
export default {
  namespace: 'HKstockM',
  state: {},
  effects: {
    //查询港股通信息
    *queryHKInfo({ payload, callback }, { call, put }) {
      const res = yield call(api.HKstock.queryHKInfo, payload);
      if (res && res.code == 0) {
        let temp = res.data.dataSource || undefined;
        if (temp) {
          temp.title = temp.stockCode + '-' + temp.stockName;
        }
        callback(temp);
      } else {
        callback();
        message.error(res ? res.msg || '查询港股通信息失败' : '查询港股通信息失败');
      }
    },
    //簿记下达
    *tradeBookSave({ payload, callback }, { call, put }) {
      const response = yield call(api.HKstock.tradeBookSave, payload);

      if (response && response.code == 0) {
        callback('success');
        message.success('簿记下达成功');
      } else {
        callback();
        message.error(response ? response.msg || '簿记下达失败' : '簿记下达失败');
      }
    },

    reducers: {
      save(state, { payload }) {
        return {
          ...state,
          ...payload,
        };
      },
    },
  },
};
